home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: news.inap.net!news1!ind-001-236-76
- From: dlmiller@iquest.net (Doug Miller)
- Subject: Re: reversing a string
- X-Nntp-Posting-Host: ind-001-236-76.iquest.net
- Message-ID: <DpnF5t.9xD@iquest.net>
- Sender: news@iquest.net (News Admin)
- Organization: IQuest Network Services
- X-Newsreader: News Xpress Version 1.0 Beta #2.1
- References: <829058514snz@genesis.demon.co.uk> <4ke0b9$rk5@grimsel.zurich.ibm.com> <DpM3Kz.6t4@iquest.net> <4kfoda$eue@grimsel.zurich.ibm.com>
- Date: Wed, 10 Apr 1996 13:39:29 GMT
-
- wgk@zurich.ibm.com (Keith Whittingham) wrote:
- >In <DpM3Kz.6t4@iquest.net>, dlmiller@iquest.net (Doug Miller) writes:
- >>wgk@zurich.ibm.com (Keith Whittingham) wrote:
- >>>Ole! (pronounced Spanishly but written 'olleh')
- >>>
- >>>Well here's a starter - no second variable but two recursive functions.
- >>>Hopefully that can be reduced to one if my project can spare the time.
- >>>(Note to manager: don't worry, just joking).
- >>>
- >>>#include <stdio.h>
- >>>
- >>>void RecRev2(char *s)
- >>> {
- >>> if(s[1])
- >>> {
- >>> if(s[2])
- >>> {
- >>> RecRev2(&s[1]);
- >>> }
- >>> s[0] ^= s[1]; s[1] ^= s[0]; s[0] ^= s[1];
- >>> }
- >>> }
- >>>
- >>>void RecRev1(char *s)
- >>> {
- >>> if(s && *s)
- >>> {
- >>> RecRev2(s);
- >>> RecRev1(&s[1]);
- >>> }
- >>> }
- >>>
- >>>int main(int argc, char *argv)
- >>> {
- >>> char *s = "Hello";
- >>> RecRev1(s);
- >>> puts(s);
- >>> return 0;
- >>> }
- >>>
- >>This breaks if the string begins and ends with the same character.
- >
- >What are you talking about?!
- >
- >Keith
- >
- >
- My mistake. I was sleeping when I wrote that. Sorry.
-